package com.pf.java.fanxing;

/**
 * 类型形参的上限
 *
 * @author pf
 * @data 2021/11/2-15:54
 */
public class Generic3 {

    public static void main(String[] args) {
        First<Integer> f1 = new First<>(100);
        System.out.println(f1.getData().doubleValue());

        First<String> f2 = new First<>("aaa");
        System.out.println(f2.getData().toString());

        Second<Integer> s1 = new Second<>(200);
        System.out.println(s1.getData().doubleValue());

//        Second<String> s2 = new Second<String>();

    }
}


// 这种无法限制
class First<Number> {

    private Number data;

    public First() {
    }

    public First(Number data) {
        this.data = data;
    }

    public Number getData() {
        return data;
    }
}


class Second<T extends Number> {
    private T data;

    public Second() {
    }

    public Second(T data) {
        this.data = data;
    }

    public T getData() {
        return data;
    }

}
